package App.Repository;

import App.Entity.Notice;
import App.Entity.NoticeCheck;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


import java.util.List;

/**
 * Created by yu on 2017/7/29.
 */
@Repository
public interface NoticeCheckRepository extends CrudRepository<NoticeCheck,Long>
{
    @Query("select noticeId from NoticeCheck check where check.receiverId= :authId")
    public List<Long> findAllNoticeIdByAuthId(@Param("authId") Long authId);

    @Query("select  noticeId from NoticeCheck check where check.receiverId=:authId and check.status=:status")
    public List<Long> findNoticeIdByAuthIdAndStatus(@Param("authId") Long authId,@Param("status") int status);

    @Query("select  noticeId from NoticeCheck check where check.receiverId=:authId and check.status=:status")
    public List<Long> findNoticeIdByAuthIdAndStatus(@Param("authId") Long authId, @Param("status") int status, Pageable pageable);

    public NoticeCheck findByReceiverIdAndNoticeId(Long receiverId,Long noticeId);

    @Query("select noticeId from NoticeCheck check where check.receiverId=:authId and check.publicTime>:time")
    public List<Long> findNoticeIdByAuthIdAndAboveTime(@Param("authId") Long authId,@Param("time")Long time);

    @Query("select  noticeId from NoticeCheck check where check.receiverId=:authId and check.projectId=:projectId and check.status=:status ")
    public List<Long> findNoticeIdByAuthIdAndProjectIdAndStatusOrderByPublicTimeDesc(@Param("authId")Long authId,@Param("projectId") Long ProjectId,@Param("status")int status);

    public List<NoticeCheck> findByReceiverIdAndProjectIdOrderByPublicTimeDesc(Long authId,Long ProjectId);

    public List<NoticeCheck> findAllByReceiverIdAndPublicTimeGreaterThanOrderByPublicTimeDesc(Long authId,Long time);
    //点对点的时候使用
    public NoticeCheck findFirstByNoticeId(Long noticeId);
}


